package gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Yaksha on 1/21/14.
 */
public class Screen extends JFrame {
    public Screen() {
        _initialize(_getScreenRes());
    }

    private void _initialize(Dimension scrLocation) {
        setBounds((int) scrLocation.getWidth(), (int) scrLocation.getHeight(), 640, 480);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().setLayout(new CardLayout());

        JMenuBar jMenuBar = new JMenuBar();
        setJMenuBar(jMenuBar);

        /*
         * Set menu components.
         */
        JMenu menuFile = new JMenu("File");
        jMenuBar.add(menuFile);

        JMenu menuEdit = new JMenu("Edit");
        jMenuBar.add(menuEdit);

        JMenu menuTool = new JMenu("Tool");
        jMenuBar.add(menuTool);

        JMenu menuHelp = new JMenu("Help");
        jMenuBar.add(menuHelp);

        /*
         * Set menu items of File
         */
        JMenuItem mntmNew = new JMenuItem("New");
        menuFile.add(mntmNew);

        JMenuItem mntmOpen = new JMenuItem("Open");
        menuFile.add(mntmOpen);

        JMenuItem mntmExit = new JMenuItem("Exit");
        mntmExit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int check = JOptionPane.showConfirmDialog(getContentPane(), "Do you wanna exit ?",
                        "Exit Dialog", JOptionPane.YES_NO_OPTION);
                System.out.println(check);
                if (check == JOptionPane.YES_OPTION) {
                    System.exit(0);
                }
            }
        });
        menuFile.add(mntmExit);


        JMenu menuSwitch = new JMenu("Switch to");
        menuTool.add(menuSwitch);

        JMenuItem mntmTab1 = new JMenuItem("Flow Layout");
        menuSwitch.add(mntmTab1);

        JMenuItem mntmTab2 = new JMenuItem("Box Layout");
        menuSwitch.add(mntmTab2);

        JMenuItem mntmTab3 = new JMenuItem("Grid Layout");
        menuSwitch.add(mntmTab3);

        JMenuItem mntmTab4 = new JMenuItem("Grid Bag Layout");
        menuSwitch.add(mntmTab4);

        /*
         * Create tab panels
         */

        FlowPanel flowPanel = new FlowPanel();
        getContentPane().add(flowPanel, "Flow Panel");
    }

    private Dimension _getScreenRes() {
        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        Dimension dimension = new Dimension(gd.getDisplayMode().getWidth() / 2 - 320,
                gd.getDisplayMode().getHeight() / 2 - 240);
        return dimension;
    }
}
